package com.auxgroup.smarthome.business.controller;

import com.auxgroup.smarthome.business.service.inner.AppVersionInnerService;
import com.auxgroup.smarthome.business.vo.AppVersionVo;
import com.auxgroup.smarthome.utils.PageContent;
import com.auxgroup.smarthome.web.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * app版本接口
 * Created by lixiaoxiao on 18-3-15.
 */
@Api(description = "app版本", tags = "app版本")
@RestController
public class AppVersionController {

    @Autowired
    private AppVersionInnerService appVersionInnerService;

    @ApiOperation(value = "获取最新的app版本信息")
    @GetMapping(value = "/app_version")
    public ApiResponse<AppVersionVo> getCurrentAppVersion() {
        return appVersionInnerService.getCurrentAppVersion();
    }

    @ApiOperation(value = "搜索app版本")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页号", paramType = "query", dataType = "int", defaultValue = "0"),
            @ApiImplicitParam(name = "size", value = "页的大小", paramType = "query", dataType = "int", defaultValue = "20"),
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "createTimeSlot", value = "创建时间段:2017-07-01~2017-08-01", paramType = "query", dataType = "string")
    })
    @GetMapping(value = "/app_versions")
    public ApiResponse<PageContent<AppVersionVo>> searchAppVersions(Integer page, Integer size, @RequestParam(value="keywords",required = false)  String keywords, @RequestParam(value="createTimeSlot",required = false)  String createTimeSlot) {
        ApiResponse<PageContent<AppVersionVo>>  apiResponse= appVersionInnerService.searchAppVersions(page, size, keywords, createTimeSlot);
        return apiResponse;
    }

    @ApiOperation(value = "新增app版本")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "version", value = "版本号", paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "build", value = "构建包", paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "link", value = "链接地址", paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "name", value = "名称", paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "description", value = "描述", paramType = "form", dataType = "string")
    })
    @PostMapping(value = "/app_version")
    public ApiResponse create(@ApiIgnore @RequestParam String version, @ApiIgnore @RequestParam Integer build, @ApiIgnore @RequestParam String link, @ApiIgnore  @RequestParam String name, @ApiIgnore @RequestParam String description) {
        return appVersionInnerService.create(version,build,link,name,description);
    }


    @ApiOperation(value = "更新app版本")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "version", value = "版本号", paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "build", value = "构建包", paramType = "form", dataType = "int"),
            @ApiImplicitParam(name = "link", value = "链接地址", paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "name", value = "名称", paramType = "form", dataType = "string"),
            @ApiImplicitParam(name = "description", value = "描述", paramType = "form", dataType = "string")
    })
    @PutMapping(value = "/app_version/{appVersionId}")
    public ApiResponse update(@PathVariable("appVersionId") String appVersionId,@ApiIgnore String version, @ApiIgnore Integer build, @ApiIgnore String link, @ApiIgnore String name, @ApiIgnore String description) {
        return appVersionInnerService.update(appVersionId, version,build,link,name,description);
    }


    @ApiOperation(value = "删除app版本")
    @DeleteMapping(value = "/app_version/{appVersionId}")
    public ApiResponse delete(@PathVariable("appVersionId") String appVersionId) {
        return appVersionInnerService.delete(appVersionId);
    }

}



